import requests


if __name__ == '__main__':
    # 用户登录
    # 搜索商品列表
    # 查询商品详情
    # 添加商品到购物车
    # 提交订单

    #定义主机路径
    url = "http://127.0.0.1:6688"
    #1.用户登录
    denglu = {"account":17631642040,"password":"taxue1997","client":2}

    resp =requests.post(url+"/api/account/login",json=denglu)
    print(resp.text)
    #提取token
    token = resp.json()["data"]["token"]
    print(token)
    #2.搜索商品列表
    sousuo = requests.get(url+"/api/goods/getGoodsList",params={"category_id":1})
    print(sousuo.text)
    #3.查询商品详情
    xiangqing =requests.get(url+"/api/goods/getGoodsDetail",params={"id":1})
    print(xiangqing.text)
    #4.添加商品到购物车
    tinajia =requests.post(url+"/api/cart/add",headers={"token":token},data={"item_id":1,"goods_num":2})
    print(tinajia.text)
    #5.提交订单
    order = {
        "action": "submit",
        "delivery_type": 1,
        "goods": [
            {
                "item_id": 18,
                "num": 1
            }
        ],
        "use_integral": 0,
        "address_id": "",
        "coupon_id": "",
        "remark": "",

    }

    tijiao =requests.post(url+"/api/order/buy",headers={"token":token},json=order)

    print(tijiao.text)